package com.example.ble_file_transfer

import android.bluetooth.BluetoothManager
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {

    companion object {
        private const val CHANNEL = "ble_file_transfer"
    }


    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(
            flutterEngine.dartExecutor.binaryMessenger,
            CHANNEL
        ).setMethodCallHandler { call, result ->

            when (call.method) {
                "isBluetoothEnable" -> result.success(isBluetoothEnable())
            }
        }

    }


    private fun isBluetoothEnable(): Boolean {
        val bluetoothManager: BluetoothManager =
            getSystemService(BluetoothManager::class.java)
        return bluetoothManager.adapter.isEnabled
    }
}
